package imagingbook.sift.scalespace;

public class DogOctave extends ScaleOctave {

	// TODO: check correctness of bottom and top levels!!
	DogOctave(ScaleOctave Gp) {
		//super(0,0,0,0);
		super(Gp.p, Gp.Q, Gp.width, Gp.height, Gp.botLevelIndex, Gp.topLevelIndex);
		// create DoG octave
		//IJ.log("making Dog Octave " );
		//IJ.log("building Dog octave " + Gp.p);
		this.botLevelIndex = Gp.botLevelIndex;
		this.topLevelIndex = Gp.topLevelIndex-1;
		for (int q = botLevelIndex; q <= topLevelIndex; q++) {
			ScaleLevel Dpq = differenceOfGaussians(Gp.getLevel(q+1), Gp.getLevel(q));
			this.setLevel(q, Dpq);
		}
	}
	
	public ScaleLevel differenceOfGaussians(ScaleLevel A, ScaleLevel B) {
		// A: Gaussian at level q+1
		// B: Gaussian at level q
		// C <-- A - B (scale the same as B)
		ScaleLevel C = B.duplicate();
		final float[] pixelsA = (float[]) A.getPixels();
		final float[] pixelsB = (float[]) B.getPixels();
		final float[] pixelsC = (float[]) C.getPixels();
		for (int i=0; i<pixelsA.length; i++) {
			pixelsC[i] = pixelsA[i] - pixelsB[i];
		}
		C.setAbsoluteScale(B.getAbsoluteScale());
		return C;
	}
	


}
